<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class CanteenRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * validation rules for user
     *
     * @return array
     */
    public function rules()
    {
        $id = $this->route('canteen');
        if($this->isMethod('post')){
            return [
                'name' => 'required|unique:canteens',
                'address' => 'required|max:255',
                'user_id'=>'required|integer'
            ];
        }else{
            return [
                'name' => 'required|unique:canteens,name,'.$id,
                'address' => 'required|max:255',
                'user_id'=>'required|integer'
            ];
        }
    }

    /**
     * Get the error messages for the defined validation rules.
     *
     * @return array
     */
    public function messages()
    {
        return [
            'name.required' => _("请输入餐厅名"),
            'name.unique'  => _("餐厅名已存在"),
            'address.required'  => _("请输入餐厅地址不能为空"),
            'user_id.required'  => _("请选择库存管理员"),
        ];
    }
}
